package com.lrr.controller;

import com.alibaba.druid.support.spring.stat.SpringStatUtils;
import com.github.pagehelper.PageInfo;
import com.lrr.entity.QueryVo;
import com.lrr.entity.Worksheet;
import com.lrr.service.WorkSheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class WorkSheetController {

    @Autowired
    WorkSheetService service;

    @RequestMapping("/list")
    public String list(QueryVo vo, @RequestParam(defaultValue = "1") Integer pageNum, Model model){
        PageInfo<Worksheet> info = service.list(vo,pageNum);
        model.addAttribute("info",info);
        model.addAttribute("vo",vo);
        return "workSheet_list";
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(String odd,Model model){
        Worksheet worksheet = service.getByOdd(odd);
        model.addAttribute("worksheet",worksheet);
        return "workSheet_update";
    }

    @RequestMapping("/update")
    public String update(Worksheet worksheet){
        service.update(worksheet);
        return "redirect:list";
    }

    @RequestMapping("/del")
    public String del(String odd){
        service.del(odd);
        return "redirect:list";
    }
}
